import { app, BrowserWindow } from 'electron'
import '../renderer/store'
import localshortcut from 'electron-localshortcut';
import os from 'os';
/**
 * Set `__static` path to static files in production
 * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
 */
if (process.env.NODE_ENV !== 'development') {
  global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}

let mainWindow
const winURL = process.env.NODE_ENV === 'development'
  ? `http://localhost:9080`
  : `file://${__dirname}/index.html`

function createWindow () {
  /**
   * Initial window options
   */
  mainWindow = new BrowserWindow({
    height: 600,
    useContentSize: true,
    width: 800,
    resizable:false,
  })

  mainWindow.loadURL(winURL)
  if(os.platform() === 'darwin') {
    localshortcut.register(`command+v`,function() {
      mainWindow.webContents.paste();
    })
    localshortcut.register(`command+c`,function() {
      mainWindow.webContents.copy();
    })
    localshortcut.register(`command+x`,function() {
      mainWindow.webContents.cut();
    })
    localshortcut.register(`command+a`,function() {
      mainWindow.webContents.selectAll();
    })
  }
  mainWindow.on('closed', () => {
    mainWindow = null
  })
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (mainWindow === null) {
    createWindow()
  }
})
